home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13319 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  54 lines

  1. Newsgroups: comp.lang.c
  2. References: <4jkq8h$1it6@useneta1.news.prodigy.com> 
  3. X-Newsreader: MicroDot 1.11beta16 [REGISTERED 000012]
  4. Mime-version: 1.0
  5. Content-Type: text/plain; charset=iso-8859-1
  6. Content-Transfer-encoding: 7BIT
  7. Path: news.gtn.com!art-line.de
  8. X-Gateway: ZCONNECT UE uuart.art-line.art-line.de [PolyNet zTOr V5.111 Serie: "retrax"]
  9. Subject: Re: File Open Problem - Please provide clues
  10. Message-ID: <xZaQmMD12aUz1@andi.art-line.de>
  11. Date: Fri,  5 Apr 96 20:52:22 GMT
  12. From: andi@art-line.de (Andreas Winkelmann)
  13.  
  14. Hi Steve.
  15.  
  16. > Hi I'm having problems with opening files which are named   
  17. > after simple numbers:                                       
  18. > 2                                                           
  19. > 5, etc.                                                     
  20. > The reason for naming them this way is because I'm writing a
  21. > program in C that increments a number, and then attempts to 
  22. > open the file that's actually named by that number.         
  23. > I get mismatched type errors when using FOPEN:              
  24. >  int num;                                                   
  25. >  filepointer = FOPEN(num,"r");            or                           
  26. >  filepointer = FOPEN("num","r");
  27.  
  28. fopen() accepts as the first argument only a stringpointer. You
  29. have to convert the number in a string.
  30.  
  31. char buffer[21];
  32. FILE *fp;
  33. int num;
  34.  
  35. sprintf( (char*)&buffer,"%ld.txt",num);
  36. fp = fopen( (char*)&buffer, "r" );
  37.  
  38. > Is there a way to manipulate an integer: store it in integer
  39. > variables, arrays, etc.., but then use that integer to open 
  40. > a file actually named by that integer?..                    
  41. >  I was going to name the files:                             
  42. >   0.txt, 1.txt, 2.txt,                                      
  43. >  and so forth, but this was even trickier with the string   
  44. > concatenating, (attached ".txt" to it) etc.. so the files   
  45. > are named after numbers simply..                            
  46.  
  47.  
  48. -----
  49. Andreas Winkelmann
  50.  
  51. E-Mail : andi@art-line.de -- MicroDot V1.11beta16
  52.  
  53.  
  54.